home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 15 / HelloWorld.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  731 b   |  27 lines

  1. /*
  2. * <applet code="HelloWorld" width=200 height=100>
  3. * </applet>
  4. *
  5. */
  6. import java.applet.*;
  7. import java.awt.*;
  8. public class HelloWorld extends Applet {
  9. final Font f = new Font("Helvetica", Font.BOLD, 18);
  10.  
  11. public void paint(Graphics g) { 
  12. Dimension d = this.size();
  13. g.setColor(Color.white);
  14. g.fillRect(0,0,d.width,d.height);
  15. g.setColor(Color.black);
  16. g.setFont(f);
  17. drawCenteredString("Hello World!", d.width, d.height, g);
  18. g.drawRect(0,0,d.width-1,d.height-1);
  19. }
  20.  
  21. public void drawCenteredString(String s, int w, int h, Graphics g) { 
  22. FontMetrics fm = g.getFontMetrics();
  23. int x = (w - fm.stringWidth(s)) / 2;
  24. int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent()))/2);
  25. g.drawString(s, x, y);
  26. } }
  27.